var createError = require('http-errors')
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var cors = require('cors');
var bodyParser = require('body-parser')

// token登录配置
var expressJWT = require('express-jwt')
var bodyparser = require('body-parser')



// var indexRouter = require('./routes/index');
// var usersRouter = require('./routes/users');

var app = express();

// token登录配置
app.use(bodyparser.json())

app.use(bodyParser.urlencoded({ extended: false }))//解析post请求
app.use(bodyParser.json())//解析json请求


// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(cors());
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/public', express.static(path.join(__dirname, 'public')));

app.use(bodyParser.urlencoded({ extended: false }))//解析post请求
app.use(bodyParser.json())//解析json请求
app.use(express.static(path.join(__dirname, 'upload')));
app.use('/public',express.static(path.join(__dirname, 'public')));
app.use("/upload",express.static(path.join(__dirname,'upload')));

// app.use('/', indexRouter);
// app.use('/users', usersRouter);
app.use('/login/index', require('./routes/appstate/Login/index.js'));
app.use('/mine/index', require('./routes/appstate/Mine/index'));
app.use('/indexs/index', require('./routes/appstate/Index/index'));
app.use('/shopcar/index', require('./routes/appstate/ShopCar/index'));
app.use('/types/index', require('./routes/appstate/Types/index'));



app.use('/login/index', require('./routes/backgroundstate/login/index'));
app.use('/total/index', require('./routes/backgroundstate/total/index'));
app.use('/analysiss/index', require('./routes/backgroundstate/analysiss/index'));
app.use('/order/index', require('./routes/backgroundstate/order/index'));
app.use('/commodity/index', require('./routes/backgroundstate/commodity/index'));
app.use('/content/index', require('./routes/backgroundstate/content/index'));
app.use('/groupjs/index', require('./routes/backgroundstate/groupjs/index'));
app.use('/finances/index', require('./routes/backgroundstate/finances/index'));
app.use('/systems/index', require('./routes/backgroundstate/systems/index'));
app.use('/operate/index', require('./routes/backgroundstate/operate/index'));
app.use('/user/index', require('./routes/backgroundstate/user/index'));

// catch 404 and forward to error handler
app.use(function (req, res, next) {
  next(createError(404));
});

// error handler
app.use(function (err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;
